<template>
	<view>
		<view class="text-center text-red bg-white" v-if="status==2&&form.remek">拒绝原因:{{form.remek}}</view>

		<view class=" padding">
			<view class="text-white padding bg radius ">
				<u-form :model="form" label-position="top">
					<u-form-item label="真实姓名 ">
						<u-input v-model="form.name" placeholder="请填写真实姓名" />
					</u-form-item>
					<u-form-item label="证件号码">
						<u-input v-model="form.idNumber" placeholder="请填写（必填）" />
					</u-form-item>
					<u-form-item label="出生日期">
						<u-input v-model="form.birth" :disabled="true" placeholder="请填写（必填）" @click="showdata=true" />
					</u-form-item>
					<u-form-item label="性别">
						<u-input v-model="sex" :disabled="true" placeholder="请填写（必填）" @click="show = true" />
					</u-form-item>
					<u-form-item label="联系方式">
						<u-input v-model="form.phone" type="number" placeholder="请填写（必填）" maxlength="11" />
					</u-form-item>
					<u-form-item label="护龄时间">
						<u-input v-model="sex" :disabled="true" placeholder="请填写（必填）" @click="show = true" />
					</u-form-item>
					<u-form-item label="地址">
						<u-input v-model="form.phone" type="number" placeholder="请填写（必填）" maxlength="11" />
					</u-form-item>
				</u-form>
			</view>

			<view class=" padding bg radius margin-top">
				<view class="text-lg">上传身份证正面</view>
				<view class="margin-top"
					style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
					<view style="text-align: center;margin: 80rpx auto 0;" @click="addImages(1)" v-if="!form.front">
						<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
						<view class="text-sm  margin-top-sm">添加身份证正面</view>
					</view>
					<image @click="disabled? '':addImages(1)" v-else :src="form.front"
						style="width: 100%;height: 320rpx;"></image>
				</view>
			</view>
			<view class="text-white padding bg radius margin-top">
				<view class="text-lg">上传身份证反面</view>
				<view class="margin-top"
					style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
					<view style="text-align: center;margin: 80rpx auto 0;" @click="addImages(2)" v-if="!form.back">
						<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
						<view class="text-sm margin-top-sm">添加身份证反面</view>
					</view>
					<image @click="disabled? '':addImages(2)" v-else :src="form.back"
						style="width: 100%;height: 320rpx;"></image>
				</view>
			</view>

			<u-button @click="submit" v-if="geRen==0||geRen == 3" class="margin-top" :custom-style="customStyle" :hair-line="false">
				提交实名
			</u-button>
		</view>

		<u-select v-model="show" :list="list" @confirm="confirm"></u-select>
		<u-picker v-model="showdata" mode="time" :params="params" @confirm="confirmData"></u-picker>

	</view>
</template>

<script>
	import configdata from '../../common/config.js';

	export default {
		data() {
			return {
				geRen: '',
				form: {
					name: '',
					idNumber: '',
					birth: '',
					sex: '',
					phone: '',
					front: '',

					back: '',

				},

				lableStyle: {
					color: '#000000',
					fontSize: '36upx'
				},
				customStyle: {
					backgroundColor: '#0175FE',
					color: '#000000',
					border: 0
				},

				renzheng: 0,
				show: false,
				list: [{
						value: '1',
						label: '男'
					},
					{
						value: '2',
						label: '女'
					}
				],
				sex: '',
				showdata: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				status:''
			}
		},
		onLoad(e) {

			this.getUserInfo()

		},
		onShow() {
			this.geRen = uni.getStorageSync("geRen")
		},
		methods: {
			confirmData(e) {
				console.log(e)
				this.form.birth = e.year + '-' + e.month + '-' + e.day
			},
			confirm(e) {
				console.log(e)
				this.sex = e[0].label
				this.form.sex = e[0].value
			},

			submit() {

				if (!this.form.name) {
					uni.showToast({
						title: '请输入真实姓名',
						icon: 'none',
						duration: 1000
					})
					return;
				}

				if (!this.form.idNumber) {
					uni.showToast({
						title: '请输入身份证号',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				// let regX =
				// 	/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
				// if (!regX.test(this.form.idNumber)) {
				// 	uni.showToast({
				// 		title: '请输入正确的身份证号',
				// 		icon: 'none',
				// 		duration: 1000
				// 	})
				// 	return;
				// }
				if (!this.form.birth) {
					uni.showToast({
						title: '请填写出生日期',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.sex) {
					uni.showToast({
						title: '请填写性别',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.phone) {
					uni.showToast({
						title: '请填写联系方式',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (!this.form.front) {
					uni.showToast({
						title: '请上传身份证正面',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if (!this.form.back) {
					uni.showToast({
						title: '请上传身份证反面',
						icon: 'none',
						duration: 1000
					})
					return;
				}

				// let data = {
				// 	name: this.form.name,
				// 	idNumber: this.form.idNumber,
				// 	front: this.form.front,
				// 	back: this.form.back,
				// 	phone: this.form.phone,
				// 	birth: this.form.birth,
				// 	sex: this.form.sex,
				// }
				this.$Request.postJson("/app/userCertification/insert", this.form).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '认证提交成功！',
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack()
						}, 1000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				});
			},
			getUserInfo() {
				this.$Request.get("/app/userCertification/queryInsert").then(res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data) {
							uni.setStorageSync("city", res.data.city)
							uni.setStorageSync("authentication", res.data.authentication)
							this.form = res.data
							this.status = res.data.status
							if (res.data.sex == 1) {
								this.sex = '男'
							}
							if (res.data.sex == 2) {
								this.form.sex = '女'
							}
						}
					}
				});
			},
			addImages(e) {
				let that = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: res => {
						for (let i = 0; i < 1; i++) {
							that.$queue.showLoading("上传中...");
							uni.uploadFile({ // 上传接口
								// url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址https://xxpwadmin.xianmxkj.com/sqx_fast/alioss/upload
								url: 'https://xicheshop.xianmxkj.com/sqx_fast/alioss/upload',
								filePath: res.tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									if (e == 1) {
										that.form.front = JSON.parse(uploadFileRes.data).data
									} else if (e == 3) {
										that.forms.front = JSON.parse(uploadFileRes.data).data
									} else if (e == 2) {
										that.form.back = JSON.parse(uploadFileRes.data).data
									} else if (e == 4) {
										if (that.classify == 1) {
											that.form.shopImg = JSON.parse(uploadFileRes.data).data
										} else if (that.classify == 2) {
											that.forms.shopImg = JSON.parse(uploadFileRes.data)
												.data
										}

									}

									uni.hideLoading();
								}
							});
						}
					}
				})
			},
			// 图片上传
			addImage() {
				let that = this
				uni.chooseImage({
					count: 6,
					sourceType: ['album', 'camera'],
					success: res => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.$queue.showLoading("上传中...");
							uni.uploadFile({ // 上传接口
								// url: that.config("APIHOST1") + '/alioss/upload', //真实的接口地址
								url: 'https://xicheshop.xianmxkj.com/sqx_fast/alioss/upload',
								filePath: res.tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									uni.hideLoading();
									// if (that.addressImg.length < 6) {
									if (that.classify == 1) {
										that.addressImg.push(JSON.parse(uploadFileRes.data)
											.data)
									}
									// } else if (that.addressImgs.length < 6) {
									else if (that.classify == 2) {
										that.addressImgs.push(JSON.parse(uploadFileRes.data)
											.data)
										console.log(that.addressImgs, '---------00')
									}
									// }
								}
							});
						}
					}
				})
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},
		}
	}
</script>

<style>
	page {
		background-color: #F7F7F7;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.u-size-default {
		background: #557EFD !important;
		color: #FFFFFF !important;
	}

	.u-input__input {
		color: balck !important;
	}

	.title_btn {
		height: 78upx;
		line-height: 78upx;
		/* background: #f7f7f7; */
	}

	.bgCol2 {
		color: #557EFD;
		background: #F2F5FF;
	}
</style>
